package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.LumiereIdcardMapper;
import org.linlinjava.litemall.db.domain.LumiereIdcard;
import org.linlinjava.litemall.db.domain.LumiereIdcardExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class LumiereIdCardService {
    @Resource
    private LumiereIdcardMapper lumiereIdcardMapper;

    public LumiereIdcard findById(Integer cardId){
        return lumiereIdcardMapper.selectByPrimaryKey(cardId);
    }

    public LumiereIdcard findByCardNo(String cardNo){
        LumiereIdcardExample example = new LumiereIdcardExample();
        LumiereIdcardExample.Criteria criteria  = example.createCriteria();
        if(cardNo != null){
            criteria.andCardNoEqualTo(cardNo);
        }

        criteria.andDeletedEqualTo(false);

        return lumiereIdcardMapper.selectOneByExample(example);
    }

    public void add(LumiereIdcard card){
        lumiereIdcardMapper.insert(card);
    }

    public List<LumiereIdcard> findByUserId(Integer userId){
        LumiereIdcardExample example = new LumiereIdcardExample();
        LumiereIdcardExample.Criteria criteria  = example.createCriteria();
        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }
        criteria.andDeletedEqualTo(false);

        return lumiereIdcardMapper.selectByExample(example);
    }

    public List<LumiereIdcard> findByUserIdAndCardNo(Integer userId,String cardNo){
        LumiereIdcardExample example = new LumiereIdcardExample();
        LumiereIdcardExample.Criteria criteria  = example.createCriteria();
        if(userId != null){
            criteria.andUserIdEqualTo(userId);
        }

        if(cardNo != null){
            criteria.andCardNoEqualTo(cardNo);
        }

        criteria.andDeletedEqualTo(false);

        return lumiereIdcardMapper.selectByExample(example);
    }

    public void delete(Integer cardId){
        lumiereIdcardMapper.logicalDeleteByPrimaryKey(cardId);
    }

}
